package com.yj.ccs.abs.web.asset.mapper;

import com.yj.ccs.abs.web.asset.entity.PropertyOwnership;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

/**
 * Copyright 2018 (C) Yunjian-VC
 * Created on : 2018/3/20
 * Author     : Unbelievable9
 **/
@Repository
@Mapper
public interface PropertyOwnershipMapper {

    @Options(useGeneratedKeys = true, keyProperty = "item.id")
    @Insert("INSERT INTO `property_ownership` (asset_id, delivery_start_date, " +
            "delivery_end_date, test_date, transfer_date, amount, unit_price, " +
            "`usage`, create_time)" +
            "VALUES (#{item.asset_id}, #{item.delivery_start_date}, " +
            "#{item.delivery_end_date}, #{item.transfer_date}, #{item.test_date}, " +
            "#{item.amount}, #{item.unit_price}, #{item.usage}, NOW())")
    void create(@Param("item") PropertyOwnership item);

    @Update("UPDATE `property_ownership` SET delivery_start_date = #{item.delivery_start_date}, " +
            "delivery_end_date = #{item.delivery_end_date}, test_date = #{item.test_date}, " +
            "transfer_date = #{item.transfer_date}, amount = #{item.amount}, " +
            "unit_price = #{item.unit_price}, `usage` = #{item.usage} " +
            "WHERE id = #{item.id}")
    void update(@Param("item") PropertyOwnership item);

    @Select("SELECT * FROM `property_ownership` WHERE id = #{id} LIMIT 1")
    PropertyOwnership getById(@Param("id") Long id);

    @Select("SELECT * FROM `property_ownership` WHERE asset_id = #{id} LIMIT 1")
    PropertyOwnership getByAssetId(@Param("id") Long id);
}
